//
//  CommonChoseItemView.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/10.
//

#import "CommonChoseItemView.h"

@implementation CommonChoseItemView
-(instancetype)initWithFrame:(CGRect)frame withTag:(NSInteger)selectTag withArray:(NSMutableArray *)dataSource withTag:(NSInteger)tag{
  self=[super initWithFrame:frame];
    if (self) {
        self.titleArray=dataSource;
        self.selectTag=selectTag;
       [self createButtonViewwithTag:tag];
    }
    return self;
}
-(void)createButtonViewwithTag:(NSInteger)tag{
   
    self.backgroundColor=White_Color;
    CGFloat buttonWidth = (ScreenWidth-136.0)/3.0;
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(120, 0, ScreenWidth-16, 58)];
    self.titleLb =[[UILabel alloc] initWithFrame:CGRectMake(16, 26, 70, 28)];
    self.titleLb.text=@"企业类型";
    self.titleLb.textColor=gray666_color;
    self.titleLb.font=[UIFont systemFontOfSize:15.0];
    [self addSubview:self.titleLb];
   
    UILabel  * xingLb =[[UILabel alloc] initWithFrame:CGRectMake(76, 26, 10, 28)];
    xingLb.text=@"*";
    xingLb.textColor=Red_Color;
    xingLb.font=[UIFont systemFontOfSize:15.0];
   [self addSubview:xingLb];

    for (int i = 0; i < self.titleArray.count; i ++) {
        int x = (10+buttonWidth)*i;
        int y = 26;
            UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];
            [button setTitle:self.titleArray[i]  forState:UIControlStateNormal];
             button.titleLabel.font=[UIFont systemFontOfSize:14.0];
            [button setTitleColor:gray666_color forState:UIControlStateNormal];
            [button setImage:Image(@"big_unSelect_icon") forState:UIControlStateNormal];
             button.frame = CGRectMake(x, y, buttonWidth, 26);
             button.tag = i + tag;
            [button addTarget:self action:@selector(selectedAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.bgView addSubview:button];
            if (button.tag==self.selectTag){
                 self.tmpBtn = button;
                [self.tmpBtn setImage:Image(@"big_selectIcon") forState:UIControlStateNormal];
            }
        }
   [self addSubview:self.bgView];

}
-(void)selectedAction:(UIButton *)sender
{
    if (self.tmpBtn == sender){
       
        [self.tmpBtn setImage:Image(@"big_unSelect_icon") forState:UIControlStateNormal];
  
    } else {

         [self.tmpBtn setImage:Image(@"big_unSelect_icon") forState:UIControlStateNormal];
          [sender setImage:Image(@"big_selectIcon") forState:UIControlStateNormal];
  
    }
     self.tmpBtn = sender;
     self.ToRefreshButtonTable(sender.tag);
}

@end
